<template>
	<view class="main"><!--添加用户-->
		<view class="userInfo">
			<view>
				<view class="tit">个人认证</view>
				<view>为了更好的服务，请填写您的个真实信息，一经认证，不能修改。请认真填写</view>
			</view>
			<image src="@/static/images/addCont.png" style="width:260rpx;" mode='widthFix'></image>
		</view>
		<view class="userForm">
			<view class="userInput"><text>真实姓名</text>
			<input placeholder="请填写你的真实姓名" v-model="form.authenName"></view>
			<view class="userInput"><text>身份证号</text>
			<input placeholder="请输入身份证号" v-model="form.authenCardId"></view>
			<view class="userInput"><text>手机号</text>
			<input placeholder="请填写你的手机号" v-model="form.authenMobile"></view>
		</view>
		<view class="userbtn">
			<view class="btn btn1" @tap="backPage">取消</view>
			<view class="btn btn2" @tap="submit">确认添加</view>
		</view>
		
	</view>
</template>
<script>
	export default {
		data() {
			return {
				form:{
					authenCardId:"",
					authenMobile:"",
					authenName:""
				}
			}
		},
		methods: {
			backPage(){
				uni.navigateBack();
			},
			submit(){
				
				if(!this.form.authenName){
					this.$tools.msg("请输入您的真实姓名")
					return;
				}
				if(this.form.authenName.length>20){
					this.$tools.msg("您的真实姓名不超过20个字符")
					return;
				}
				if(!this.form.authenMobile){
					this.$tools.msg("请输入您的电话号码")
					return;
				}
				if(!this.tools.validatePhoneNumber(this.form.authenMobile)){
					this.$tools.msg("请输入正确的手机号")
					return;
				}
				if(!this.form.authenCardId){
					this.$tools.msg("请输入您的身份证码号")
					return;
				}
				if (!this.$tools.checkParity(this.form.authenCardId)) {
					this.$tools.msg('请输入正确的身份证号')
					return false
				}
				this.$http.addMyAuthen(this.form).then(res=>{
					console.log(res);
					if(res.code==0){
						this.$tools.msg("认证成功！")
						this.$store.dispatch("getLoginUser").then(res=>{
							uni.navigateBack();		 
						})
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	@import url("@/css/app.scss");
	
	.main{min-height: 100vh;background-color:  #e7fcf5;}
	
</style>
